package br.edu.unifei.mestrado.commons.partition;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import br.edu.unifei.mestrado.commons.graph.RelationshipWrapper;

/**
 * Armazena os nós internos de um set. <br>
 * Armazena os nós da fronteira que estão ligados ao nós internos desse set. <br>
 * 
 * @author roberto
 * 
 */
public class EdgeCache {

	private int id;

	/**
	 * id_vertice | edge
	 * 
	 * Lista de edges que já entraram no set
	 */
	private Map<Long, RelationshipWrapper> mapEdges = new HashMap<Long, RelationshipWrapper>();
	private int edgeCut;

	public EdgeCache(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public void addEdge(RelationshipWrapper edge) {
		RelationshipWrapper rel = mapEdges.put(edge.getId(), edge);
		if(rel == null) {
			edgeCut += edge.getWeight();
		}
	}

	public void removeEdge(RelationshipWrapper edge) {
		RelationshipWrapper rel = mapEdges.remove(edge.getId());
		if(rel != null) {
			edgeCut -= edge.getWeight();
		}
	}
	
	public int getEdgeCut() {
		return edgeCut;
	}
	
	public Collection<RelationshipWrapper> getEdges() {
		return mapEdges.values();
	}
	
	@Override
	public String toString() {
		return "SET_" + id + " E: " + mapEdges.size();
	}

}
